import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import cesium from "vite-plugin-cesium";

let loading = function () {
  return {
    name: "loading",
    transformIndexHtml(html) {
      const loading = [
        {
          tag: "link",
          attrs: {
            rel: "stylesheet",
            href: "./loading.css",
          },
        },
      ];
      return loading;
    },
  };
};

export default defineConfig({
  base: "./",
  build: {
    outDir: "web3d",
    chunkSizeWarningLimit: 1000,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes("node_modules")) {
            return id
              .toString()
              .split("node_modules/")[1]
              .split("/")[0]
              .toString();
          }
        },
      },
    },
  },
  server: {
    open: "/",
    port: 3000,
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    cesium(),
    loading(),
  ],
});
